package cn.tedu.knows.search.controller;

import cn.tedu.knows.search.VO.QuestionVO;
import cn.tedu.knows.search.service.IQuestionService;
import com.github.pagehelper.PageInfo;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/v3/questions")
public class QuestionController {
    @Resource
    private IQuestionService questionService;

    @PostMapping
    public PageInfo<QuestionVO> search(String key, Integer pageNum, @AuthenticationPrincipal UserDetails user) {
        if (pageNum == null)
            pageNum = 1;
        Integer pageSize = 8;
        PageInfo<QuestionVO> pageInfo = questionService.search(key, user.getUsername(), pageNum, pageSize);
        return pageInfo;
    }
}
